<?php include_once("../../common/common_setting_unit.php");         // 引入通用的设置文件 ?>
<?php include_once('controller/data_edit.php'); ?>
<?php include_once(ROOT_PATH_ . "/controller/common/module/head.php"); // 引入通用的头部 ?>
<?php include_once("term-select-list-function.php"); ?>
<?php include_once("detail-function.php"); ?>


<style>
.layui-input-block {
margin-left: 120px!important;
}
.layui-form-label {
width: 120px!important;
}
</style>





    <body>
<div id="topbar">
      <!--TopBar端點01-->
      <?php include ROOT_PATH_ . '/controller/common/module/topbar.php'; ?>      <!--TopBar端點02-->
    </div>
<div id="container">
      <!--Container端點01-->
      <div id="maincontent"    class="detail">
    <!--maincontent端點01-->

    <div id="sidebar">
          <?php include ROOT_PATH_ . '/controller/common/module/sidebar.php'; ?>
        </div>
    <div id="content">
          <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>
        <h1>编辑 : <? echo $detail['name'] ?> </h1>
        </legend>
      </fieldset>
          <div class="detail-box <? echo $system_part ?>">
        <div class="detail-boxes">
              <ul class="detail-boxing">
            <form id="detail_detail_form" method="post"
      class="layui-form  layui-form-pane"
      action="detail-edit-function.php?now_extender=<? echo $system_part ?>"
      enctype="multipart/form-data" name="uploadfile" >
                  <input type="hidden"  name="nid" value="<? echo $detail['nid']?>" >
                  <fieldset class="layui-elem-field layui-field-title" id="content1" style="margin-top: 30px;">
                <legend>基本信息</legend>
              </fieldset>
                  <blockquote class="layui-elem-quote">基本信息多数是对外使用的资料，请细心填写。</blockquote>
                  <br/>
                  <li class="layui-form-item name">
                <label class="layui-form-label">名称：</label>
                <div class="layui-input-block">
                      <input type="text" class="layui-input"  name="ai_name"  value="<? echo $detail['name'] ?>">
                    </div>
                <em class="explain">(<u
            style="color:red">*必填项目</u>,
                    填写标题) </em> </li>
                  <li class="layui-form-item short_desc" style="display: none">
                <label class="layui-form-label">短简介：</label>
                <div class="layui-input-block">
                      <input type="text" class="layui-input" name="ai_short_desc" size="20" value="<?php echo $detail_short_desc?>">
                    </div>
                <em class="explain">(填写短简介)</em> </li>
                  <li class="layui-form-item model" style="display: none">
                <label class="layui-form-label">型号：</label>
                <div class="layui-input-block">
                      <input type="text" class="layui-input"  name="ai_model" size="20" value="<? echo $detail['module'] ?>">
                    </div>
                <em class="explain">填写您自己设置的型号，型号不作排序</em> </li>
                  <?php
	$sql = "select count(*) as term_count from ".$table_Prefix."term  where publish = 1 and belong = '".$system_part."' ";

	$term_res = mysql_query($sql);

	$term_count = mysql_fetch_assoc($term_res);

?>
                  <li class="layui-form-item term">
                      <label class="layui-form-label">所属分类：</label>
                      <div class="layui-input-block">

                      <?php
	if($term_count['term_count'] == 0){
	?>
                <a href="../detail/term-add.php?now_extender=<?php echo $system_part;?>" class="threeDbtn layui-btn ">添加分类</a>
                <?php
	}
	else{
	?>
                <div style="float:left;">
                      <? include("mod-term-select.php");?>
                    </div>
                <em class="explain">(选择对应的分类，可多选。)</em>
                <?php
	}
	?>
                      </div>

                  </li>
                  <?php
	$sql = "select count(*) as brand_count from ".$table_Prefix."term  where publish = 1 and belong = 'brand' ";

	$brand_res = mysql_query($sql);

	$brand_count = mysql_fetch_assoc($brand_res);

?>









                  <div class="brand layui-form-item">
                <label class="layui-form-label">所属品牌： </label>
                <div class="layui-input-block">
                      <?php if(count($brand_list) == 0){?>
                      <a href="/controller/extender/brand/view/term-add.php?now_extender=brand" class="threeDbtn layui-btn ">添加品牌</a>
                      <?php;} else{?>
                      <div style="float:left;">
                    <? include("mod-brand-select.php");?>
                  </div>
                      <em class="explain">(选择对应的品牌，可多选。)</em>
                      <?php;}?>
                    </div>
              </div>





                  <li class="layui-form-item publish">
                <label class="layui-form-label">发布状态：</label>
                <div class="layui-input-block">
                      <input name='ai_publish' type='radio' value='1'  title="立即发布" <?if($detail['publish'] == '1'){echo "checked='checked'";}?>/>
                      <input name='ai_publish' type='radio' value='0'  title="暂未发布" <?if($detail['publish'] == '0'){echo "checked='checked'";}?>/>
                    </div>
              </li>


                  <li class="layui-form-item inputtime" >
                <label class="layui-form-label">发布时间：</label>
                <div class="layui-input-block">
                      <input type="text" class="layui-input" id="<? echo $detail['inputtime']; ?>" name="ai_inputtime" size="20"
                                              value="<?

											  if(strpos($detail['inputtime'], "-") != false){
												 echo $detail['inputtime'];
											  }
											  else{
												 echo date("Y-m-d H:i:s", $detail['inputtime']);
											   }
											   ?>
                                              "
                                              onclick="laydate({istime: true,elem: '#ai_inputtime', format: 'YYYY-MM-DD hh:mm:ss' })"
                                              class="laydate-icon">
                    </div>
                <em class="explain">(填写发布的时间)</em>
                  </li>


                <hr/>




                <div class="function">

                <button class="layui-btn "  lay-submit type="button" lay-filter="formSub">立即提交</button>
                <input type="reset" class="layui-btn" value="重置"/>
                <input name="sys_part" type="hidden" value="<? echo $system_part ?>"/>
                <input name="nowpageid" type="hidden" value="<? echo $_REQUEST['nowpageid'] ?>"/>
                <input name="brand_id" type="hidden" value="<? echo $_REQUEST['brand_id'] ?>"/>
                <input name="sortby" type="hidden" value="<? echo $_REQUEST['sortby'] ?>"/>
                <input name="term_nid" type="hidden" value="<? echo $_REQUEST['term_nid'] ?>"/>

                <input type="hidden" name="cat_list_json" id="cat_list_json" />
                <input type="hidden" name="brand_list_json" id="brand_list_json" />

                </div>

                </form>
          </ul>
            </div>
      </div>

          <!--content端點01-->
        </div>
    <!--maincontent端點01-->
    <br class="clearfloat"/>
  </div>
      <!--container端點01-->
    </div>
<?php include  ROOT_PATH_."/controller/modules/footer.php"; ?>
<script>
var filePath_ = "/uploadfiles/" + "<?php echo $theme_folder?>" + "/";
//上传视频开关
var videoUploadSwitch_ = false;
 function dropImg(imgId)
{
   $.ajax({
			type:"POST",
			url:"ajax_delete_detail_img_attr.php",
			dateType:"json",
			data:{"nid":imgId},
			dataType:"json",
			beforeSend: function () {

			   index =  layer.msg('正在删除中，请稍等', {
				  icon: 16,
				  shade:true,
				  time:10000,
				  shade: [0.8, '#393D49']
				},function(){

				});


			 },
			success:function(data){
				if(data.error == 1){

					var msg_box = layer.msg(data.message, {
					  icon: 5,
					  shade:true,
					  time:1000,
					  shade: [0.8, '#393D49']
					});
					//
				}
				else{
					$('#gallery_'+imgId).remove()

				}
			},
			complete: function (XHR, TS) {layer.close(index);    XHR = null ; $('.search_btn').removeAttr("disabled"); } ,

		})
}


var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);


 function addImg(obj)
  {
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  }

  /**
   * 鍒犻櫎鍥剧墖涓婁紶
   */
  function removeImg(obj)
  {
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');

      tbl.deleteRow(row);
  }

  function rowindex(tr)
{
  if (Browser.isIE)
  {
    return tr.rowIndex;
  }
  else
  {
    table = tr.parentNode.parentNode;
    for (i = 0; i < table.rows.length; i ++ )
    {
      if (table.rows[i] == tr)
      {
        return i;
      }
    }
  }
}

$('.search_btn').click(
	function(){

		/*$.each($("input[name='article_type[]']"), function(i,val){

			 alert(val.name);
			 alert(val.value);
		});*/
		 search_val = '';
		 $.each($("input[name='article_type[]']:checked"),function(){
              select_val = $(this).val();
			  if(search_val.length > 0){
				 search_val=search_val+','+select_val;
			  }
			  else{
				 search_val=select_val;
			  }
        });

			$.ajax({
			type:"POST",
			url:"ajax_search_detail.php?act=search_detail",
			dateType:"json",
			data:{"val":search_val},
			dataType:"json",
			beforeSend: function () {

				$('.search_btn').attr({ disabled: "disabled" });

			   index =  layer.msg('正在查询中，请稍等', {
				  icon: 16,
				  shade:true,
				  time:10000,
				  shade: [0.8, '#393D49']
				},function(){

				});


			 },
			success:function(data){
				if(data.error == 1){

					var msg_box = layer.msg(data.message, {
					  icon: 5,
					  shade:true,
					  time:1000,
					  shade: [0.8, '#393D49']
					});
					//
				}
				else{
					layui.use(['transfer', 'layer', 'util'], function(){
					  var $ = layui.$
					  ,transfer = layui.transfer
					  ,layer = layui.layer
					  ,util = layui.util;


					  //模拟数据
					  var data1 = data.content

					   transfer.reload('detail_attr_list', {
						  data: data1
						});

					});

				}
			},
			complete: function (XHR, TS) {layer.close(index);    XHR = null ; $('.search_btn').removeAttr("disabled"); } ,

		})

	}
)




$(document).ready(function(e) {



 layui.use(['transfer', 'layer', 'util', 'form', 'tree'], function(){
	  var $ = layui.$
	  ,transfer = layui.transfer
	  ,layer = layui.layer
	  ,util = layui.util
	  ,tree = layui.tree
	  ,form = layui.form;


	var data1 = <?php echo $json_data;?>  //显示搜索框
	transfer.render({
			elem: '#test4'
			,showSearch: true
			,height:300
			,width:600
			,data: data1
			,title: ['全选', '全选']


			,id: 'detail_attr_list'
			,value: [<?php echo $detail_relation_list;?>]
	})

     var data5 = <?php echo $json_goods_list;?>  //显示搜索框
             transfer.render({
                 elem: '#test5'
                 ,data: data5
                 ,title: ['全选', '全选']
                 ,showSearch: true
                 ,height:300
                 ,width:600
                 ,id: 'goods_attr_list'
                 ,value: [<?php echo $goods_relation_list;?>]
             })


	<?php

	if( $detail_relation_list_json){?>
	var select_json = <?php echo $detail_relation_list_json;?>

	 setRightPosition(select_json, '#test4');
	<?php }

     if( $goods_relation_list_json){?>
         var select_json5 = <?php echo $goods_relation_list_json;?>

                 setRightPosition(select_json5, '#test5');
         <?php }?>



	  form.on('submit(formSub)', function(data){

		 if($('#cat_list').length > 0){

			var checkData = tree.getChecked('cat_list');
			$('#cat_list_json').val(JSON.stringify(checkData))
		 }

		 if($('#brand_list').length > 0){
		 	 var checkbrandData = tree.getChecked('brand_list');
			 $('#brand_list_json').val(JSON.stringify(checkbrandData))
		 }

		 if($('#shop_list').length > 0){
		 	 var checkshopData = tree.getChecked('shop_list');
			 $('#shop_list_json').val(JSON.stringify(checkshopData))
		 }

			var ul = $("#test4").find("ul").eq(1);
			var input = $(ul).find("input");
			var saveArr = [];
			for(var i = 0; i < input.length; i++) {
				var inJson = {};

				inJson["title"] = input[i].title;
				inJson["value"] = input[i].value;
				saveArr.push(inJson);
			}
			json_data= JSON.stringify(saveArr)
          $('#detail_attr').val(json_data)

          var ul5 = $("#test5").find("ul").eq(1);
          var input5 = $(ul5).find("input");
          var saveArr5 = [];
          for(var i = 0; i < input5.length; i++) {
              var inJson5 = {};

              inJson5["title"] = input5[i].title;
              inJson5["value"] = input5[i].value;
              saveArr5.push(inJson5);
          }

          json_data5= JSON.stringify(saveArr5)

          $('#goods_attr').val(json_data5)


			$('.layui-form-pane').submit()
	  })

	});


});

function get_id(data){

	for(var c = 0; c < data.length; c++) {

		if(data.children.length){

		}
		inJson["value"] = checkData[i].value;

		save_cat_id_Arr.push(cat_inJson);
	}

}
//上移
		function moveUp(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent();
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				if(index.eq(i).index()!=0){
					 index.eq(i).prev().before(index.eq(i));
				}
			}

		}

		//置顶
		function moveUpMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent();
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				do{
					index.eq(i).prev().before(index.eq(i));
				}while(index.eq(i).index()!=0)
			}
		}

		//下移
		function moveDown(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent();
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				if(index.eq(i).index()!=($("#"+dom+" ul li").length-1)){
					 index.eq(i).next().after(index.eq(i));
				}
			}
		}

		//置底
		function moveDownMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent();
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				do{
					index.eq(i).next().after(index.eq(i));
				}while(index.eq(i).index()!=($("#"+dom+" ul").eq(1).find("li").length-1))
			}
		}

		//穿梭框加载时不会按照设定的顺序来，需要删除重载
		function setRightPosition(json,dom) {
			var index = $(dom+ " ul").eq(1);

			var list = json;
			var str = "";

			if(list){
				for(var i = 0; i < list.length; i++) {
					var inObj = list[i];

					var tagName = inObj.title;
					var htmlStr = $(index).children().children("input[title='"+tagName+"']").parent().prop("outerHTML");

					str += htmlStr;
				}
			}
			$(dom+" ul").eq(1).empty();
			$(dom+" ul").eq(1).append(str);

		}

</script>

</div>

</body>
</html>
